package com.system.training.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.system.training.dao.TrainingRepository;
import com.system.training.entity.Training;

@Service
@Transactional
public class TrainingService implements ITrainingService{
	@Autowired
	private TrainingRepository trainingRepository;
	
	
	public void saveOrUpdate(Training training) {
		trainingRepository.save(training);
	}

	public void delete(Training training) {
		trainingRepository.delete(training);
	}

	@Transactional(readOnly = true)
	public Training findOne(Long id) {
		return trainingRepository.findById(id);
	}

	@Transactional(readOnly = true)
	public List<Training> findAll() {
		return (List<Training>) trainingRepository.findAll();
	}
	
	@Override
	public Page<Training> findAll(Specification<Training> spec, Pageable pageable) {
		return trainingRepository.findAll(spec, pageable);
	}
	
	@Override
	public void delete(List<Long> ids) {
		List<Training> trainings =  (List<Training>) trainingRepository.findAll(ids);
		if(trainings!=null) {
			trainingRepository.delete(trainings);
		}
	}

	
}
